Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The date-fns npm package provides a comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js. It offers a variety of functions to parse, validate, manipulate, and format dates.
Parsing Dates
Parse strings in ISO format to JavaScript Date objects.
const parseISO = require('date-fns/parseISO');
const result = parseISO('2023-04-12');
Formatting Dates
Format Date objects into strings with a given format.
const format = require('date-fns/format');
const result = format(new Date(2023, 3, 12), 'yyyy-MM-dd');
Comparing Dates
Compare two dates to determine if one comes before the other.
const isBefore = require('date-fns/isBefore');
const result = isBefore(new Date(2023, 3, 12), new Date(2023, 3, 13));
Manipulating Dates
Perform date calculations such as adding or subtracting time spans.
const addDays = require('date-fns/addDays');
const result = addDays(new Date(2023, 3, 12), 10);
Validating Dates
Check if a date is valid.
const isValid = require('date-fns/isValid');
const result = isValid(new Date('2023-04-12'));
Moment.js is a legacy project, now in maintenance mode, which provides similar functionalities for parsing, validating, manipulating, and formatting dates. It's more object-oriented and mutable compared to the functional and immutable design of date-fns.
Day.js is a lightweight date library that offers a similar API to Moment.js but with a smaller footprint. It is immutable and chainable, like date-fns, but with a different plugin system for extending functionality.
Luxon is a powerful, modern, and chainable library for working with dates and times. It offers a rich set of features for parsing, formatting, manipulating, and querying dates. It's built on the Intl API and provides time zone support out of the box, which is more comprehensive than date-fns's approach to time zones.
Pinned: see a brief comparison with Moment.js.
date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
date-fns is like lodash for dates. It has 140+ functions for all occasions.
dateFns.format(new Date(2014, 1, 11), 'MM/DD/YYYY')
//=> '02/11/2014'
var dates = [new Date(1995, 6, 2), new Date(1987, 1, 11), new Date(1989, 6, 10)]
dates.sort(dateFns.compareAsc)
//=> [
// Wed Feb 11 1987 00:00:00,
// Mon Jul 10 1989 00:00:00,
// Sun Jul 02 1995 00:00:00
// ]
The library is available as an npm package, a Bower package. To install a package run:
npm install date-fns --save
# or with yarn
yarn add date-fns
# or with bower
bower install date-fns
Also, you can simply download the library from the releases page.
See date-fns.org for more details, API, and other docs.
[1.30.1] - 2018-12-10
Fixed DST issue. See #972 and #992 for more details. This fix was backported from v2.
Fix a few bugs that appear in timezones with offsets that include seconds (e.g. GMT+00:57:44). See PR #789. This fix was backported from v2.
Fixed misspelled January in the Thai locale. Thanks to @ratchapol-an!
Added Serbian locale. Kudos to @mawi12345!
Added Belarusian locale. Kudos to @mawi12345 again!
FAQs
Modern JavaScript date utility library
The npm package date-fns receives a total of 14,696,240 weekly downloads. As such, date-fns popularity was classified as popular.
We found that date-fns demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.